package models

import (
	"class-server/basic/config"
	"gorm.io/gorm"
	"time"
)

type Collect struct {
	Id        uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	UserId    uint           `gorm:"column:user_id;type:bigint UNSIGNED;not null;default:0;" json:"user_id"`
	ClassesId uint           `gorm:"column:classes_id;type:bigint UNSIGNED;not null;default:0;" json:"classes_id"`
	TypesId   uint           `gorm:"column:types_id;type:bigint;not null;" json:"types_id"`
	Price     uint           `gorm:"column:price;type:int UNSIGNED;not null;default:0;" json:"price"`
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (col *Collect) TableName() string {
	return "collect"
}

// 添加收藏
func (col *Collect) Create() error {
	return config.DB.Create(&col).Error
}

// 查看收藏
func (col *Collect) GetCollectDetail() error {
	return config.DB.Where("id = ?", col.Id).Limit(1).Find(&col).Error
}
